import ServiceBase from '../base';
import AccountModelProxy from '../proxies/account-model-proxy';
import {AccountPageProxy, PublicAccountInfoProxy} from '../proxies/account-page-proxy';
import {AccountEmailInscribeProxy, AccountProfileProxy} from '../proxies/account-profile-proxy';
import * as proxy from '../proxy';

const GET_ACCOUNT = '/accounts';

class AccountService extends ServiceBase {
    getAllAccounts = (data) => {
        let promise = super.get({
            url: GET_ACCOUNT,
            params: data,
        });
        return proxy.httpResultProxy(promise, AccountPageProxy);
    };
    getAccountByAccountId = (data) => {
        let promise = super.get({
            url: `${GET_ACCOUNT}/${data.accountId}`,
        });
        return proxy.httpResultProxy(promise, AccountModelProxy);
    };
    getAccountPublicInfo = (data) => {
        let promise = super.getWithoutToken({
            url: `${GET_ACCOUNT}/${data.accountId}/publicInfo`,
        });
        return proxy.httpResultProxy(promise, PublicAccountInfoProxy);
    };
    // POST 新建企业组织
    addAccount = (data) => {
        let promise = super.post({
            url: GET_ACCOUNT + `/enterprise`,
            data,
        });
        return proxy.httpResultProxy(promise);
    };
    shiftAccountActive = (data) => {
        let promise = super.put({
            url: `${GET_ACCOUNT}/${data.accountId}/state`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };
    updateAccount = (data) => {
        let promise = super.put({
            url: GET_ACCOUNT + `/${data.accountId}`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, AccountModelProxy);
    };
    createPersonalAccount = () => {
        let promise = super.post({
            url: GET_ACCOUNT + `/personal`,
        });
        return proxy.httpResultProxy(promise, AccountModelProxy);
    };
    // PUT /accounts/{accountId}/mailInscribe 修改 Account 的邮件落款信息
    updateAccountMailInscribe = (data) => {
        let promise = super.put({
            url: `${GET_ACCOUNT}/${data.accountId}/mailInscribe`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, AccountEmailInscribeProxy);
    };
    // GET /accounts/{accountId}/mailInscribe 获取 Account 的邮件落款信息
    getQuillEditorContent = (data) => {
        let promise = super.get({
            url: `${GET_ACCOUNT}/${data.accountId}/mailInscribe`,
        });
        return proxy.httpResultProxy(promise, AccountEmailInscribeProxy);
    };
    getPublicAccounts = () => {
        let promise = super.get({
            url: GET_ACCOUNT + `?open=true`,
        });
        return proxy.httpResultProxy(promise, AccountPageProxy);
    };
    setUserToAccountAdmin = (data) => {
        let promise = super.post({
            url: `${GET_ACCOUNT}/${data.accountId}/admin`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };
    getAccountProfile = (accountId) => {
        let promise = super.get({
            url: GET_ACCOUNT + `/${accountId}/profile`,
        });
        return proxy.httpResultProxy(promise, AccountProfileProxy);
    };
    newAccountProfile = (data) => {
        let promise = super.post({
            url: GET_ACCOUNT + `/${data.accountId}/profile`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, AccountProfileProxy);
    };
    updateAccountProfile = (data) => {
        let promise = super.put({
            url: GET_ACCOUNT + `/${data.accountId}/profile`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, AccountProfileProxy);
    };
    // 扩展属性
    getExtendCategories = (data) => {
        let promise = super.get({
            url: `${GET_ACCOUNT}/${data.accountId}/extattrs/categories`,
        });
        return proxy.httpResultProxy(promise);
    };
    getExtendAttrResource = (data) => {
        let promise = super.get({
            url: `${GET_ACCOUNT}/${data.accountId}/extattrs/resources`,
        });
        return proxy.httpResultProxy(promise);
    };
    addExtendCategories = (data) => {
        let promise = super.post({
            url: `${GET_ACCOUNT}/${data.accountId}/extattrs/categories`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };
    updateExtendCategory = (data) => {
        let promise = super.put({
            url: `${GET_ACCOUNT}/${data.accountId}/extattrs/categories/${data.categoryId}`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };
    deleteExtendCategory = (data) => {
        let promise = super.delete({
            url: `${GET_ACCOUNT}/${data.accountId}/extattrs/categories/${data.categoryId}`,
        });
        return proxy.httpResultProxy(promise);
    };
    addExtendAttribute = (data) => {
        let promise = super.post({
            url: `${GET_ACCOUNT}/${data.accountId}/extattrs/categories/${data.categoryId}/entries`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };
    updateExtendAttribute = (data) => {
        let promise = super.put({
            url: `${GET_ACCOUNT}/${data.accountId}/extattrs/categories/${data.categoryId}/entries/${data.entryId}`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };
    deleteExtendAttribute = (data) => {
        let promise = super.delete({
            url: `${GET_ACCOUNT}/${data.accountId}/extattrs/categories/${data.categoryId}/entries/${data.entryId}`,
        });
        return proxy.httpResultProxy(promise);
    };
    ascendExtendedAttribute = (data) => {
        let promise = super.put({
            url: `${GET_ACCOUNT}/${data.accountId}/extattrs/categories/${data.categoryId}/entryorders`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };
    // GET 按组织名称搜索组织
    searchAccounts = (data) => {
        let promise = super.get({
            url: `${GET_ACCOUNT}/search`,
            params: data,
        });
        return proxy.httpResultProxy(promise, AccountPageProxy);
    }
}

export {AccountService};
